package com.scanner;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

@SuppressLint("NewApi")
public abstract class BaseTiltView extends View {
	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
	Path path = null;
	Point point1_draw;
	Point point2_draw;
	Point point3_draw;
	
	Point screenSize;
	
	final double leftThreshold = 0.3;
	final double rightThreshold = 0.7;
	final double headThreshold = 0.9;
	final double triangleBaseThreshold = 0.7;
	final double headCenter = 0.5;
	
	protected boolean clearFlag = false;
	
	
	public BaseTiltView(Context context)
	{
		super(context);
		paint.setStrokeWidth(2);
	    paint.setARGB(120, 0, 250, 120);     
	    paint.setStyle(Paint.Style.FILL_AND_STROKE);
	    paint.setAntiAlias(true);
	    
	    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	    Display display = wm.getDefaultDisplay();
	    screenSize = new Point();
	    display.getSize(screenSize);
	    
	    SetPoints();
	    
		setWillNotDraw(false);
		
	}
	
	abstract void SetPoints();
	
	@Override
	public void	onDraw(Canvas canvas)
	{
		if (!clearFlag)
		{
			if (path == null)
			{
				path = new Path(); 
			    path.setFillType(Path.FillType.EVEN_ODD);
			    path.moveTo(point1_draw.x,point1_draw.y);
			    path.lineTo(point2_draw.x,point2_draw.y);
			    path.lineTo(point3_draw.x,point3_draw.y);
			    path.lineTo(point1_draw.x,point1_draw.y);
			    path.close();
			}
			
			canvas.drawPath(path, paint);
		}
	}
	
	public void ClearView()
	{
		clearFlag = true;
		this.invalidate();
		clearFlag = false;
	}

}
